package com.unytech.wisdomcommunity.mainfragment;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.unytech.wisdomcommunity.R;
import com.viewpagerindicator.TabPageIndicator;

/**
 * Created by zed on 2016/11/2/0027.
 */

/**
 * "商家"fragment
 */
public class BusinessFragment2 extends BaseFragment2 {
    public BusinessFragment2(){

    }
    private TabPageIndicator mTabPageIndicator;
    private String[] title = {"享美食","住酒店","爱玩乐","全部"};
    @Override
    protected int getContentLayoutRes() {
        return R.layout.business_fragment;
    }

    @Override
    protected void initView(View childView) {
        ViewPager viewPager = (ViewPager) childView.findViewById(R.id.shop_vp);
        mTabPageIndicator = (TabPageIndicator)childView.findViewById(R.id.shop_tpi);

        viewPager.setAdapter(mPageAdapter);
        mTabPageIndicator.setViewPager(viewPager);
    }
    public PagerAdapter mPageAdapter = new PagerAdapter() {
        @Override
        public int getCount() {
            return title ==null?0:title.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            // return super.instantiateItem(container, position);

            TextView textView = new TextView(container.getContext());
            textView.setText(title[position]);
//            textView.setText(mShowNewsCategories.get(position).title);
            textView.setTextSize(80);
            textView.setGravity(Gravity.CENTER);
            container.addView(textView);
            return textView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            //super.destroyItem(container, position, object);
            container.removeView((View) object);
        }
    };
}